home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------*\
- | qa.c - A template for a Windows application |
- | |
- | History: |
- | 01/01/88 toddla Created |
- | |
- \*----------------------------------------------------------------------------*/
-
- #include <windows.h>
- #include <windowsx.h>
- #include <commdlg.h>
- #include <mmsystem.h> // for timeGetTime()
- #include <stdlib.h> // for rand()
- #include "qa.h"
- #include "dib.h"
- #include "tblt.h"
- #include "trle.h"
-
- #ifdef WIN32
- //
- // unless you have Win32s 1.1 timeGetTime() does not work
- //
- #define timeGetTime() GetTickCount()
- #endif
-
- /*----------------------------------------------------------------------------*\
- | |
- | g l o b a l v a r i a b l e s |
- | |
- \*----------------------------------------------------------------------------*/
- static char szAppName[]="Transparent App";
- static char szAppFilter[]="Bitmaps\0*.bmp;*.dib\0All Files\0*.*\0";
-
- static HINSTANCE hInstApp;
- static HWND hwndApp;
- static HACCEL hAccelApp;
- static HPALETTE hpalApp;
- static BOOL fAppActive;
-
- #ifdef WIN32
- #define _export
- #endif
-
- static UINT DibUsage;
- static LPBITMAPINFOHEADER lpbiApp;
- static LPBITMAPINFOHEADER lpbiRle;
- static HBITMAP hbmApp;
- static HBITMAP hbmMaskC;
- static HBITMAP hbmMaskM;
- static HBITMAP hbmB;
- static HDC hdcApp;
- static HDC hdcMaskC;
- static HDC hdcMaskM;
- static HDC hdcB;
-
- typedef void (*PDrawSprite)(HDC hdc, int x, int y);
-
- void DrawSpriteMaskM(HDC hdc, int x, int y);
- void DrawSpriteMaskC(HDC hdc, int x, int y);
- void DrawSpriteMaskT(HDC hdc, int x, int y);
- void DrawSpriteMask(HDC hdc, int x, int y);
- void DrawSpriteRLE(HDC hdc, int x, int y);
-
- static PDrawSprite DrawSprite;
- static UINT RandomSeed;
- static BOOL gfClipping = FALSE;
- static BOOL gfOffscreen = FALSE;
-
- BOOL IsWin32s()
- {
- return LOBYTE(GetVersion()) == 3 && (GetVersion() & 0x80000000l);
- }
-
- BOOL InitMaskBlt() {return !IsWin32s();}
-
- //
- // table of posible sprite drawers.
- //
- struct {
- PDrawSprite Draw;
- BOOL (*Init)(void);
- char * szName;
- } aDraw[] = {
- DrawSpriteMaskC,NULL, "Color Mask",
- DrawSpriteMaskM,NULL, "Mono Mask",
- DrawSpriteMaskT,NULL, "True Mask",
- DrawSpriteRLE, NULL, "RLE Sprite",
- #ifdef WIN32
- DrawSpriteMask, InitMaskBlt,"MaskBlt",
- #endif
- };
-
- #define NUM_DRAW (sizeof(aDraw) / sizeof(aDraw[0]))
-
- /*----------------------------------------------------------------------------*\
- \*----------------------------------------------------------------------------*/
- void SetDraw(int i)
- {
- char ach[128];
-
- if (aDraw[i].Draw == NULL)
- return;
-
- DrawSprite = aDraw[i].Draw;
- wsprintf(ach, "%s - %s", (LPSTR)szAppName, (LPSTR)aDraw[i].szName);
- SetWindowText(hwndApp, ach);
- }
-
- /*----------------------------------------------------------------------------*\
- | |
- | f u n c t i o n d e f i n i t i o n s |
- | |
- \*----------------------------------------------------------------------------*/
-
- LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
- int ErrMsg (LPSTR sz,...);
- LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
-
- void AppExit(void);
- BOOL AppIdle(void);
- void AppOpenFile(HWND hwnd, LPSTR szFileName);
-
- /*----------------------------------------------------------------------------*\
- | AppAbout( hDlg, uiMessage, wParam, lParam ) |
- | |
- | Description: |
- | This function handles messages belonging to the "About" dialog box. |
- | The only message that it looks for is WM_COMMAND, indicating the use |
- | has pressed the "OK" button. When this happens, it takes down |
- | the dialog box. |
- | |
- | Arguments: |
- | hDlg window handle of about dialog window |
- | uiMessage message number |
- | wParam message-dependent |
- | lParam message-dependent |
- | |
- | Returns: |
- | TRUE if message has been processed, else FALSE |
- | |
- \*----------------------------------------------------------------------------*/
- BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
- {
- switch (msg)
- {
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK)
- {
- EndDialog(hwnd,TRUE);
- }
- break;
-
- case WM_INITDIALOG:
- return TRUE;
- }
- return FALSE;
- }
-
- /*----------------------------------------------------------------------------*\
- | AppInit( hInst, hPrev) |
- | |
- | Description: |
- | This is called when the application is first loaded into |
- | memory. It performs all initialization that doesn't need to be done |
- | once per instance. |
- | |
- | Arguments: |
- | hInstance instance handle of current instance |
- | hPrev instance handle of previous instance |
- | |
- | Returns: |
- | TRUE if successful, FALSE if not |
- | |
- \*----------------------------------------------------------------------------*/
- BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
- {
- WNDCLASS cls;
- int dx,dy;
- int i;
-
- /* Save instance handle for DialogBoxs */
- hInstApp = hInst;
-
- hAccelApp = LoadAccelerators(hInst, "AppAccel");
-
- if (!hPrev)
- {
- /*
- * Register a class for the main application window
- */
- cls.hCursor = LoadCursor(NULL,IDC_ARROW);
- cls.hIcon = LoadIcon(hInst,"AppIcon");
- cls.lpszMenuName = "AppMenu";
- cls.lpszClassName = szAppName;
- cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- cls.hInstance = hInst;
- cls.style = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
- cls.lpfnWndProc = (WNDPROC)AppWndProc;
- cls.cbWndExtra = 0;
- cls.cbClsExtra = 0;
-
- if (!RegisterClass(&cls))
- return FALSE;
- }
-
- dx = GetSystemMetrics (SM_CXSCREEN) / 2;
- dy = GetSystemMetrics (SM_CYSCREEN) / 2;
-
- hwndApp = CreateWindow (szAppName, // Class name
- szAppName, // Caption
- WS_OVERLAPPEDWINDOW, // Style bits
- CW_USEDEFAULT, 0, // Position
- dx,dy, // Size
- (HWND)NULL, // Parent window (no parent)
- (HMENU)NULL, // use class menu
- hInst, // handle to window instance
- (LPSTR)NULL // no params to pass on
- );
- ShowWindow(hwndApp,sw);
-
- if (*szCmdLine)
- AppOpenFile(hwndApp, szCmdLine);
- else
- AppOpenFile(hwndApp, "Herman");
-
- RandomSeed = (UINT)timeGetTime();
- srand(RandomSeed);
-
- //
- // init every thing.
- //
- for (i=0; i<NUM_DRAW; i++)
- {
- if (aDraw[i].Init && !aDraw[i].Init())
- aDraw[i].Draw = NULL;
- }
-
- //
- // build the draw menu.
- //
- HMENU hmenu = GetSubMenu(GetMenu(hwndApp), 1);
- DeleteMenu(hmenu, MENU_DRAW, MF_BYCOMMAND);
-
- for (i=0; i<NUM_DRAW; i++)
- {
- AppendMenu(hmenu, 0, MENU_DRAW+i, aDraw[i].szName);
- }
-
- AppendMenu(hmenu, MF_SEPARATOR, -1, NULL);
- AppendMenu(hmenu, 0, MENU_CLIP, "Clipping");
- AppendMenu(hmenu, 0, MENU_OFFSCREEN, "Offscreen");
-
- // pick a default.
- SetDraw(0);
-
- return TRUE;
- }
-
-
- /*----------------------------------------------------------------------------*\
- | AppExit() |
- | |
- | Description: |
- | app is just about to exit, cleanup |
- | |
- \*----------------------------------------------------------------------------*/
- void AppExit()
- {
- AppOpenFile(hwndApp, NULL);
- }
-
- /*----------------------------------------------------------------------------*\
- \*----------------------------------------------------------------------------*/
-
- #define RandRGB() RGB(rand() % 256, rand() % 256, rand() % 256)
- #define RandPT(pt, rc) ((pt).x = rc.left + (rand() % (rc.right-rc.left))), ((pt).y = rc.top + (rand() % (rc.bottom-rc.top)))
-
- RECT rcSprite;
-
- void DoSprite(HDC hdc=NULL, LONG l=0)
- {
- POINT pt;
- BOOL fGetDC;
-
- if (fGetDC = (hdc == NULL))
- {
- hdc = GetDC(hwndApp);
-
- SelectPalette(hdc, hpalApp, FALSE);
- RealizePalette(hdc);
-
- if (gfOffscreen)
- {
- SelectPalette(hdcB, hpalApp, FALSE);
- RealizePalette(hdcB);
- }
- }
-
- if (l == 0)
- RandPT(pt, rcSprite);
- else
- pt.x = LOWORD(l), pt.y = HIWORD(l);
-
- if (gfOffscreen)
- {
- BitBlt(hdcB, 0, 0, DibWidth(lpbiApp), DibHeight(lpbiApp), hdc, pt.x, pt.y, SRCCOPY);
- DrawSprite(hdcB, 0, 0);
- BitBlt(hdc, pt.x, pt.y, DibWidth(lpbiApp), DibHeight(lpbiApp), hdcB, 0, 0, SRCCOPY);
- }
- else
- {
- DrawSprite(hdc, pt.x, pt.y);
- }
-
- if (fGetDC)
- ReleaseDC(hwndApp, hdc);
-
- if (fGetDC && gfOffscreen)
- SelectPalette(hdcB, (HPALETTE)GetStockObject(DEFAULT_PALETTE), FALSE);
- }
-
- /*----------------------------------------------------------------------------*\
- | TimeIt() |
- \*----------------------------------------------------------------------------*/
-
- #define N 100
-
- #define FPS(time,n) \
- time ? (1000l * n / time) : 0, \
- time ? (1000000l * n / time) % 1000: 0
-
- static char achMsg[4000];
-
- void TimeIt()
- {
- HDC hdc;
- LONG time;
- int i,n;
- char *pch;
- HCURSOR hcur;
-
- InvalidateRect(hwndApp, NULL, TRUE);
- UpdateWindow(hwndApp);
-
- hdc = GetDC(hwndApp);
-
- SelectPalette(hdc, hpalApp, FALSE);
- RealizePalette(hdc);
-
- if (gfOffscreen)
- {
- SelectPalette(hdcB, hpalApp, FALSE);
- RealizePalette(hdcB);
- }
-
- SetStretchBltMode(hdc, COLORONCOLOR);
-
- hcur = SetCursor(NULL);
-
- pch = achMsg;
-
- for (n=0; n<NUM_DRAW; n++)
- {
- if (aDraw[n].Draw == NULL)
- continue;
-
- SetDraw(n);
- srand(RandomSeed);
-
- time = timeGetTime();
-
- for (i=0; i<N; i++)
- DoSprite(hdc);
-
- time = timeGetTime() - time;
-
- pch += wsprintf(pch, "%-20s\t%ld.%03ld fps\n", (LPSTR)aDraw[n].szName, FPS(time,N));
- }
-
- SetCursor(hcur);
- ReleaseDC(hwndApp, hdc);
-
- SetDraw(0);
- MessageBox(hwndApp,achMsg,szAppName,MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
- }
-
- /*----------------------------------------------------------------------------*\
- | WinMain( hInst, hPrev, lpszCmdLine, cmdShow ) |
- | |
- | Description: |
- | The main procedure for the App. After initializing, it just goes |
- | into a message-processing loop until it gets a WM_QUIT message |
- | (meaning the app was closed). |
- | |
- | Arguments: |
- | hInst instance handle of this instance of the app |
- | hPrev instance handle of previous instance, NULL if first |
- | szCmdLine ->null-terminated command line |
- | cmdShow specifies how the window is initially displayed |
- | |
- | Returns: |
- | The exit code as specified in the WM_QUIT message. |
- | |
- \*----------------------------------------------------------------------------*/
- int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
- {
- MSG msg;
-
- /* Call initialization procedure */
- if (!AppInit(hInst,hPrev,sw,szCmdLine))
- return FALSE;
-
- /*
- * Polling messages from event queue
- */
- for (;;)
- {
- if (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
- {
- if (msg.message == WM_QUIT)
- break;
-
- if (hAccelApp && TranslateAccelerator(hwndApp, hAccelApp, &msg))
- continue;
-
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else
- {
- if (AppIdle())
- WaitMessage();
- }
- }
-
- AppExit();
- return msg.wParam;
- }
-
- /*----------------------------------------------------------------------------*\
- | AppIdle() |
- | |
- | Description: |
- | place to do idle time stuff. |
- | |
- | Returns: |
- | RETURN TRUE IF YOU HAVE NOTHING TO DO OTHERWISE YOUR APP WILL BE A |
- | CPU PIG! |
- \*----------------------------------------------------------------------------*/
- BOOL AppIdle()
- {
- if (fAppActive)
- {
- //
- // dont draw while tracking.
- //
- if (GetCapture() == hwndApp)
- return TRUE;
-
- //
- // we are the foreground app, so draw randomly
- //
- if (lpbiApp && DrawSprite)
- {
- DoSprite();
- return FALSE;
- }
-
- return TRUE; // nothing to do.
- }
- else
- {
- //
- // we are a background app.
- //
- return TRUE; // nothing to do.
- }
- }
-
- /*----------------------------------------------------------------------------*\
- | AppOpenFile() |
- | |
- | Description: |
- | open a file stupid |
- | |
- \*----------------------------------------------------------------------------*/
- void AppOpenFile(HWND hwnd, LPSTR szFileName)
- {
- HDC hdc;
-
- if (hpalApp)
- DeleteObject(hpalApp);
-
- if (hdcApp)
- DeleteObject(hdcApp);
-
- if (hdcMaskC)
- DeleteObject(hdcMaskC);
-
- if (hdcB)
- DeleteObject(hdcB);
-
- if (hdcMaskM)
- DeleteObject(hdcMaskM);
-
- if (hbmApp)
- DeleteObject(hbmApp);
-
- if (hbmMaskC)
- DeleteObject(hbmMaskC);
-
- if (hbmB)
- DeleteObject(hbmB);
-
- if (hbmMaskM)
- DeleteObject(hbmMaskM);
-
- if (lpbiApp)
- DibFree(lpbiApp);
-
- if (lpbiRle)
- DibFree(lpbiRle);
-
- hpalApp = NULL;
- lpbiApp = NULL;
- hbmApp = NULL;
- hbmMaskC = NULL;
- hbmMaskM = NULL;
- hdcApp = NULL;
- hdcMaskC = NULL;
- hdcMaskM = NULL;
-
- if (szFileName == NULL)
- return;
-
- lpbiApp = DibOpenFile(szFileName);
-
- if (lpbiApp == NULL)
- {
- ErrMsg("Cant open %s", szFileName);
- return;
- }
-
- //
- // get the palette
- //
- hpalApp = DibCreatePalette(lpbiApp);
-
- //
- // make this a identity palette for fast drawing.
- //
- MakeIdentityPalette(hpalApp);
- DibMapToPalette(lpbiApp, hpalApp);
-
- //
- // convert to a bitmap
- //
- hbmApp = BitmapFromDib(lpbiApp, hpalApp, DIB_RGB_COLORS);
-
- //
- // now make a trans mask.
- //
- hbmMaskM = MakeTransMask(hbmApp, hpalApp, -1); // mono mask
-
- //
- // make a transparent RLE
- //
- lpbiRle = MakeRleDib(lpbiApp, -1);
-
- hdc = GetDC(NULL);
-
- //
- // we will use DIB_PAL_COLORS to draw dibs on a palette device.
- //
- if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
- {
- DibUsage = DIB_PAL_COLORS;
- DibSetUsage(lpbiRle, hpalApp, DIB_PAL_COLORS);
- }
-
- //
- // make memory DCs for easy access.
- //
- hdcApp = CreateCompatibleDC(hdc);
- hdcMaskM = CreateCompatibleDC(hdc);
- hdcMaskC = CreateCompatibleDC(hdc);
- hdcB = CreateCompatibleDC(hdc);
- hbmB = CreateCompatibleBitmap(hdc, DibWidth(lpbiApp), DibHeight(lpbiApp));
- hbmMaskC = CreateCompatibleBitmap(hdc, DibWidth(lpbiApp), DibHeight(lpbiApp));
-
- ReleaseDC(NULL, hdc);
-
- SelectObject(hdcApp, hbmApp);
- SelectObject(hdcB, hbmB);
- SelectObject(hdcMaskM, hbmMaskM);
- SelectObject(hdcMaskC, hbmMaskC);
-
- // convert mask to color.
- BitBlt(hdcMaskC, 0, 0, DibWidth(lpbiApp), DibHeight(lpbiApp), hdcMaskM, 0, 0, SRCCOPY);
-
- SendMessage(hwndApp, WM_SIZE, 0, 0);
- }
-
- /*----------------------------------------------------------------------------*\
- | AppPaint(hwnd, hdc) |
- | |
- | Description: |
- | The paint function. Right now this does nothing. |
- | |
- | Arguments: |
- | hwnd window painting into |
- | hdc display context to paint to |
- | |
- | Returns: |
- | nothing |
- | |
- \*----------------------------------------------------------------------------*/
- AppPaint (HWND hwnd, HDC hdc)
- {
- return TRUE;
- }
-
- /*----------------------------------------------------------------------------*\
- | AppWndProc( hwnd, uiMessage, wParam, lParam ) |
- | |
- | Description: |
- | The window proc for the app's main (tiled) window. This processes all |
- | of the parent window's messages. |
- | |
- \*----------------------------------------------------------------------------*/
- LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- BOOL f;
- int i;
-
- switch (msg)
- {
- case WM_CREATE:
- break;
-
- case WM_ACTIVATEAPP:
- fAppActive = (BOOL)wParam;
-
- //
- // on Win32/NT or Win32c (not Win32s) we can use DIB_PAL_INDICES
- // when in the foreground because we converted our DIB color
- // table to match the system palette 1:1 when we loaded it.
- // and we are using a "identity" palette.
- //
- #ifdef WIN32
- if (!IsWin32s() && DibUsage != DIB_RGB_COLORS)
- DibUsage = fAppActive ? DIB_PAL_INDICES : DIB_PAL_COLORS;
- #endif
- break;
-
- case WM_TIMER:
- break;
-
- case WM_ERASEBKGND:
- break;
-
- case WM_INITMENU:
- for (i=0; i<NUM_DRAW; i++)
- {
- EnableMenuItem((HMENU)wParam, MENU_DRAW + i, aDraw[i].Draw ? MF_ENABLED : MF_GRAYED);
- CheckMenuItem((HMENU)wParam, MENU_DRAW + i, DrawSprite == aDraw[i].Draw ? MF_CHECKED : MF_UNCHECKED);
- }
-
- CheckMenuItem((HMENU)wParam, MENU_CLIP, gfClipping ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_OFFSCREEN, gfOffscreen ? MF_CHECKED : MF_UNCHECKED);
- break;
-
- case WM_COMMAND:
- return AppCommand(hwnd,msg,wParam,lParam);
-
- case WM_DESTROY:
- hAccelApp = NULL;
- PostQuitMessage(0);
- break;
-
- case WM_SIZE:
- GetClientRect(hwnd, &rcSprite);
-
- if (lpbiApp == NULL)
- return 0L;
-
- if (!gfClipping)
- {
- if ((int)DibWidth(lpbiApp) < rcSprite.right)
- rcSprite.right -= DibWidth(lpbiApp);
-
- if ((int)DibHeight(lpbiApp) < rcSprite.bottom)
- rcSprite.bottom -= DibHeight(lpbiApp);
- }
- else
- {
- rcSprite.left -= DibWidth(lpbiApp);
- rcSprite.right += DibWidth(lpbiApp);
- rcSprite.top -= DibHeight(lpbiApp);
- rcSprite.bottom += DibHeight(lpbiApp);
- }
- break;
-
- case WM_CLOSE:
- break;
-
- case WM_PALETTECHANGED:
- if ((HWND)wParam == hwnd)
- break;
-
- // fall through to WM_QUERYNEWPALETTE
-
- case WM_QUERYNEWPALETTE:
- hdc = GetDC(hwnd);
-
- if (hpalApp)
- SelectPalette(hdc, hpalApp, FALSE);
-
- f = RealizePalette(hdc);
- ReleaseDC(hwnd,hdc);
-
- if (f)
- InvalidateRect(hwnd,NULL,TRUE);
-
- return f;
-
- case WM_PAINT:
- hdc = BeginPaint(hwnd,&ps);
- AppPaint (hwnd,hdc);
- EndPaint(hwnd,&ps);
- return 0L;
-
- case WM_MOUSEMOVE:
- if ((UINT)wParam & MK_LBUTTON)
- DoSprite(NULL, (LONG)lParam);
- break;
-
- case WM_LBUTTONDOWN:
- SetCapture(hwnd);
- DoSprite(NULL, (LONG)lParam);
- break;
-
- case WM_LBUTTONUP:
- ReleaseCapture();
- break;
- }
- return DefWindowProc(hwnd,msg,wParam,lParam);
- }
-
- /*----------------------------------------------------------------------------*\
- | AppCommand(hwnd, msg, wParam, lParam ) |
- | |
- | Description: |
- | handles WM_COMMAND messages for the main window (hwndApp) |
- | of the parent window's messages. |
- | |
- \*----------------------------------------------------------------------------*/
- LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
- {
- static char achFileName[128];
- static OPENFILENAME ofn;
- int i;
-
- switch(LOWORD(wParam))
- {
- case MENU_ABOUT:
- DialogBox(hInstApp,"AppAbout",hwnd,AppAbout);
- break;
-
- case MENU_OPEN:
- achFileName[0] = 0;
-
- /* prompt user for file to open */
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = hwnd;
- ofn.hInstance = NULL;
- ofn.lpstrFilter = szAppFilter;
- ofn.lpstrCustomFilter = NULL;
- ofn.nMaxCustFilter = 0;
- ofn.nFilterIndex = 0;
- ofn.lpstrFile = achFileName;
- ofn.nMaxFile = sizeof(achFileName);
- ofn.lpstrFileTitle = NULL;
- ofn.nMaxFileTitle = 0;
- ofn.lpstrInitialDir = NULL;
- ofn.lpstrTitle = NULL;
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
- ofn.nFileOffset = 0;
- ofn.nFileExtension = 0;
- ofn.lpstrDefExt = NULL;
- ofn.lCustData = 0;
- ofn.lpfnHook = NULL;
- ofn.lpTemplateName = NULL;
-
- if (GetOpenFileName(&ofn))
- {
- AppOpenFile(hwnd,achFileName);
- }
-
- break;
-
- case MENU_EXIT:
- PostMessage(hwnd,WM_CLOSE,0,0L);
- break;
-
- case MENU_TIME:
- TimeIt();
- break;
-
- case MENU_CLIP:
- gfClipping = !gfClipping;
- PostMessage(hwnd, WM_SIZE, 0, 0);
- break;
-
- case MENU_OFFSCREEN:
- gfOffscreen = !gfOffscreen;
- break;
-
- default:
- i = (int)LOWORD(wParam) - MENU_DRAW;
-
- if (i >= 0 && i < NUM_DRAW && aDraw[i].Draw)
- SetDraw(i);
-
- InvalidateRect(hwnd, NULL, TRUE);
- break;
- }
- return 0L;
- }
-
- void DrawSpriteMaskM(HDC hdc, int x, int y)
- {
- TransMaskBlt(hdc, x, y, DibWidth(lpbiApp), DibHeight(lpbiApp),
- hdcApp, hdcMaskM, 0, 0);
- }
-
- void DrawSpriteMaskT(HDC hdc, int x, int y)
- {
- TrueMaskBlt(hdc, x, y, DibWidth(lpbiApp), DibHeight(lpbiApp),
- hdcApp, hdcMaskM, 0, 0);
- }
-
- void DrawSpriteMaskC(HDC hdc, int x, int y)
- {
- TransMaskBlt(hdc, x, y, DibWidth(lpbiApp), DibHeight(lpbiApp),
- hdcApp, hdcMaskC, 0, 0);
- }
-
- void DrawSpriteRLE(HDC hdc, int x, int y)
- {
- DibDraw(hdc,x,y,-1,-1,lpbiRle,0,0,-1,-1,SRCCOPY,DibUsage);
- }
-
- #ifdef WIN32
- void DrawSpriteMask(HDC hdc, int x, int y)
- {
- MaskBlt(hdc, x, y, DibWidth(lpbiApp), DibHeight(lpbiApp),
- hdcApp, 0, 0, hbmMaskM, 0, 0, 0xCCAA0000);
- }
- #endif
-
- /*----------------------------------------------------------------------------*\
- | ErrMsg - Opens a Message box with a error message in it. The user can |
- | select the OK button to continue |
- \*----------------------------------------------------------------------------*/
- int ErrMsg (LPSTR sz,...)
- {
- static char ach[128];
-
- wvsprintf (ach,sz,(LPSTR)(&sz+1)); /* Format the string */
- MessageBox(hwndApp,ach,szAppName,MB_OK|MB_ICONEXCLAMATION|MB_TASKMODAL);
- return FALSE;
- }
-
- /*****************************************************************************
- *
- * dprintf() is called by the DPF macro if DEBUG is defined at compile time.
- *
- * The messages will be send to COM1: like any debug message. To
- * enable debug output, add the following to WIN.INI :
- *
- * [debug]
- * QA=1
- *
- ****************************************************************************/
-
- #ifdef DEBUG
-
- #define MODNAME "QA"
-
- #ifndef WIN32
- #define lstrcatA lstrcat
- #define lstrcpyA lstrcpy
- #define lstrlenA lstrlen
- #define wvsprintfA wvsprintf
- #define GetProfileIntA GetProfileInt
- #define OutputDebugStringA OutputDebugString
- #endif
-
- #define _WINDLL
- #include <stdarg.h>
-
- void FAR CDECL dprintf(LPSTR szFormat, ...)
- {
- char ach[128];
- va_list va;
-
- static BOOL fDebug = -1;
-
- if (fDebug == -1)
- fDebug = GetProfileIntA("Debug", MODNAME, TRUE);
-
- if (!fDebug)
- return;
-
- lstrcpyA(ach, MODNAME ": ");
- va_start(va, szFormat);
- wvsprintfA(ach+lstrlenA(ach),szFormat,(LPSTR)va);
- va_end(va);
- lstrcatA(ach, "\r\n");
-
- OutputDebugStringA(ach);
- }
-
- #endif
-